﻿@model dynamic
@using Newtouch.Infrastructure;
@{
    ViewBag.Title = "站点统计";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<style>
    .form .formTitle {
        position: relative;
        text-align: right;
        white-space: nowrap;
        font-weight: normal;
        width: 55px;
        padding-right: 15px;
    }
</style>
<link rel="stylesheet" type="text/css" href="~/Content/css/bootstrap-multiselect.css">
<script type="text/javascript" src="~/Content/js/bootstrap-multiselect.js"></script>
<div class="topPanel">
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
        <div class="btn-group">
            <a class="btn btn-primary" onclick="btn_add()"><i class="fa fa-plus"></i>新建</a>
        </div>
        <div class="btn-group">
            <a id="inputedit" class="btn btn-primary" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改</a>
        </div>
        <div class="btn-group">
            <a id="inputdel" class="btn btn-primary" onclick="btn_delete()"><i class="fa fa-pencil-square-o"></i>删除</a>
        </div>
    </div>
    <div style="height:45px !important;">
        <table class="form" style="width:750px;height:45px !important;">
            <tr>
                <td class="formTitle">
                    机构：
                </td>
                <td class="formValue" style="width:125px;">
                    <select id="siteId" name="siteId" class="form-control" multiple="multiple">
                    </select>
                </td>
                <th class="formTitle">年份：</th>
                <td class="formValue" style="width:75px;">
                    <select id="year" name="year" class="form-control" style="width:65px">
                        <option value="-1">全部</option>
                    </select>
                </td>
                <th class="formTitle">月份：</th>
                <td class="formValue" style="width:75px;">
                    <select id="month" name="month" class="form-control" style="width:65px">
                        <option value="-1">全部</option>
                    </select>
                </td>
                <th class="formTitle">审核状态：</th>
                <td class="formValue" style="width:65px;">
                    @Html.DropDownList("shzt", Newtouch.Infrastructure.EnumOrgshzt.DS.ToDescSelectList(), "全部", new { @class = "newform-control form-control required", @style = "width: 100%;" })
                </td>
                <td>
                    <input type="button" id="btn_search" class="btn btn-md btn-primary form-an" value="查询" style="margin-left:35px;width:50px" />
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>
<script lang="javascript">

    //年月下拉初始化
    (function initYearMonthSelect() {
        var date = new Date;
        //默认选择上个月
        var defaultSelYear = 1900 + date.getYear();
        var defaultSelMonth = date.getMonth();
        if (defaultSelMonth == 0) {
            defaultSelYear--;
            defaultSelMonth = 12;
        }
        //年份
        $("#year").newtouchBindSelect({
            datasource: function () {
                var resultObjArr = new Array();
                if (top.clients.yearArr && top.clients.yearArr.length) {
                    $.each(top.clients.yearArr, function () {
                        resultObjArr.push({ id: this, text: this });
                    });
                }
                return resultObjArr;
            },
            selectedValue: defaultSelYear,
        });
        //月份
        $("#month").newtouchBindSelect({
            datasource: function () {
                var resultObjArr = new Array();
                if (top.clients.monthArr && top.clients.monthArr.length) {
                    $.each(top.clients.monthArr, function () {
                        resultObjArr.push({ id: this, text: parseInt(this) < 10 ? "0" + this : this });
                    });
                }
                return resultObjArr;
            },
            selectedValue: defaultSelMonth,
        });

    })();

    $(function () {
        $("#siteId").multiselect("destroy").multiselect({
            url: "@Url.Action("getCurrentOrgIds")",
            selectedValue: 'all',
            includeSelectAllOption: false,
            enableClickableOptGroups: true,
            enableCollapsibleOptGroups: true,
            selectAllText: "全选",
            nonSelectedText: "未选中",
            allSelectedText: "全选",
            onBuiltAsyncOptions: function (res) {
                // 这里的代码是ajax创建完成options之后执行
                $("#siteId").trigger("change");
                gridList();
            },
        });
      
        $('#siteId,#year,#month,#shzt').change(function () {
            $("#btn_search").trigger("click");
        });
        
    });

    //get data
    function gridList() {
        var $gridList = window.$("#gridList");
        $gridList.dataGrid({
            url: "/SiteManage/SiteStatistics/GetIndexGridJson",
            height: window.$(window).height() - 120,
            postData: getSearchData(),
            colModel: [
                { label: "主键", name: "Id", hidden: true, key: true },
                { label: '站点', name: 'zdmc', width: 150, align: 'left' },
                { label: '统计年份', name: 'year', width: 60, align: 'center' },
                { label: '统计月份', name: 'month', width: 50, align: 'center' },
                {
                    label: '系统中收入(元)', name: 'zsr', width: 100, align: 'right',
                    formatter: 'number', formatoptions: { thousandsSeparator: ",", decimalPlaces: 2 }
                },
                {
                    label: '核实收入(元)', name: 'hssr', width: 90, align: 'right',
                    formatter: 'number', formatoptions: { thousandsSeparator: ",", decimalPlaces: 2 }
                },
                {
                    label: '差额(元)', name: 'ce', width: 80, align: 'right',
                    formatter: 'number', formatoptions: { thousandsSeparator: ",", decimalPlaces: 2 }
                },
                {
                    label: '共担成本(元)', name: 'gdcb', width: 100, align: 'right',
                    formatter: 'number', formatoptions: { thousandsSeparator: ",", decimalPlaces: 2 }
                },
                {
                    label: 'GRS成本(元)', name: 'grscb', width: 90, align: 'right',
                    formatter: 'number', formatoptions: { thousandsSeparator: ",", decimalPlaces: 2 }
                },
                {
                    label: '机构收入(元)', name: 'jgss', width: 90, align: 'right',
                    formatter: 'number', formatoptions: { thousandsSeparator: ",", decimalPlaces: 2 }
                },
                {
                    label: 'GRS收入(元)', name: 'grsss', width: 90, align: 'right',
                    formatter: 'number', formatoptions: { thousandsSeparator: ",", decimalPlaces: 2 }
                },
                {
                    label: '审核状态', name: 'shzt', width: 60, align: 'center',
                    formatter: function (cellvalue) {
                        return $.enum.getDescByValue("EnumOrgshzt", cellvalue);
                    }
                },
                {
                    label: '操作', name: 'action', width: 60, align: 'center',
                    formatter: function (cellvalue, options, rowObject) {
                        return "<a style=\"text-decoration:underline\" color:blue onclick=\"btn_detail('" + rowObject.Id + "')\">详情</a>";
                    }
                }],
            pager: "#gridPager",
            sortname: 'Id',
            viewrecords: true,
            unwritten: false,
            ondblClickRow: function () {
                btn_edit();
            }, onSelectRow: function (rowid, status) {
                var shzt = $("#gridList").jqGridRowValue().shzt;
                if (shzt == "通过" || shzt == "待审" || shzt == "预提交") {
                    if (shzt != "预提交") {
                        $('#inputedit').attr('disabled', true);
                    }
                    $('#inputdel').attr('disabled', 'disabled');
                } else {
                    $('#inputedit').removeAttr('disabled', 'disabled');
                    $('#inputdel').removeAttr('disabled', 'disabled');
                }
            }
        });

        //查询
        $("#btn_search").click(function () {
            $("#gridList").jqGrid('setGridParam', {
                postData: getSearchData(),
            }).trigger('reloadGrid');
        });
    }

    function getSearchData() {
        var siteId = $('#siteId').val() == null ? "" : $('#siteId').val().join(',');
        var year = $('#year').val();
        var month = $('#month').val();
        var shzt = $('#shzt').val();
        return { siteId: siteId , year: year, month: month, shzt: shzt };
    }

    //新增
    function btn_add() {
        window.$.modalOpen({
            id: "Form",
            title: "新增收支统计表",
            url: "/SiteManage/SiteStatistics/Form",
            width: "1000px",
            height: "580px",
            btn: null
        });
    }

    //修改
    function btn_edit() {
        var keyValue = $("#gridList").jqGridRowValue().Id;
        if (!!!keyValue) {
            $.modalAlert("请选中一条信息", 'warning');
            return false;
        }
        if ($("#gridList").jqGridRowValue().shzt !== "预提交"&&$("#gridList").jqGridRowValue().shzt !== "未提交" && $("#gridList").jqGridRowValue().shzt !== "未通过") {
            return false;
        }
        $.modalOpen({
            id: "updateForm",
            title: "修改站点收支统计表",
            url: "/SiteManage/SiteStatistics/Form?keyValue=" + keyValue,
            width: "1000px",
            height: "580px",
            btn: null
        });
    }
    //查看详情
    function btn_detail(keyValue) {
         if (!!!keyValue) {
            $.modalAlert("请选中一条信息", 'warning');
            return false;
        }
        $.modalOpen({
            id: "Form",
            title: "查看收支统计表",
            url: "/SiteManage/SiteStatistics/VerifySiteStatisticsDetail?keyValue=" + keyValue+"&from=index",
            width: "1000px",
            height: "580px",
            btn: null,
        });
    }

    //删除
    function btn_delete() {
        window.$.modalConfirm("确定要删除吗？", function (flag) {
            if (!flag) {
                return false;
            }
            return true;
        });
        var keyValue = window.$("#gridList").jqGridRowValue().Id;
        if (!!!keyValue) {
            window.$.modalAlert("请选中一条信息", 'warning');
            return false;
        }
        window.$.deleteForm({
            url: "/SiteManage/SiteStatistics/DeleteForm",
            param: { keyValue: keyValue },
            success: function () {
                $.modalMsg("删除成功","success");
                $('#gridList').jqGrid("clearGridData"); //清除明细的grid
                $("#btn_search").trigger("click");
            }
        });
        return true;
    }
</script>